IF exists(SELECT * FROM dbo.sysobjects WHERE name='prognoseTotalenPerRichting2' AND xtype='V') 
BEGIN
	DROP VIEW prognoseTotalenPerRichting2
END
GO

create view prognoseTotalenPerRichting2
as
select b.studieKeuzePrognose, l.klas, Sum(1) as totaal
from leerlingen as l 
	left join keuzeTeksten2 as b 
	  on l.inschrijvingsNr = b.inschrijvingsNr
group by b.studieKeuzePrognose, l.klas